package com.zmm.weblog.common.domain.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zmm.weblog.common.domain.dos.ArticleContentDo;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface ArticleContentMapper extends BaseMapper<ArticleContentDo> {

    /**
     * 根据文章ID删除记录
     */
    default int deleteByArticleId(Long articleId) {
        return delete(Wrappers.<ArticleContentDo>lambdaQuery()
                .eq(ArticleContentDo::getArticleId, articleId));
    }

    default ArticleContentDo selectByArticleId(Long articleId) {
        return selectOne(Wrappers.<ArticleContentDo>lambdaQuery()
                .eq(ArticleContentDo::getArticleId, articleId));
    }

    /**
     * 通过文章ID更新
     * @param articleContentDO
     * @return
     */
    default int updateByArticleId(ArticleContentDo articleContentDO){
        return update(articleContentDO, Wrappers.<ArticleContentDo>lambdaUpdate()
                .eq(ArticleContentDo::getArticleId, articleContentDO.getArticleId()));
    }

}